< previous page page_655 next page >

Page 655
0655-01.jpg
Figure 17.3.
Attempting to open a locked table.
You can perform the same table-locking operation by using this Visual Basic code:
Sub OpenTable()
    On Error GoTo OpenTableErr
    '
    Dim db As Database
    Dim rs As Recordset
    '
    Set db = DBEngine.OpenDatabase("C:\TYSDBVB5\SOURCE\DATA\MULTIUSE.MDB")
    Set rs = db.OpenRecordset("MasterTable", dbOpenTable,
    _dbDenyRead + dbDenyWrite)
    '
    GoTo OpenTableExit
    '
OpenTableErr:
    MsgBox Error$(Err) + Chr(13) + "Exiting Program", vbCritical, "OpenTable"
    GoTo OpenTableExit
    '
OpenTableExit:
    '
End Sub
Notice the use of the dbDenyRead and dbDenyWrite constants in the OpenRecordset method. This is the same as setting the Option property of the data control to 3. Also notice that an error trap is added to the module to replace the code in the Error event of the data control.

 
< previous page page_655 next page >

If you like this book, buy it!